package edu.gxmzu.task.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import edu.gxmzu.task.entity.Work1;
import edu.gxmzu.task.entity.Works;
import edu.gxmzu.task.params.AdminWorkParam;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 莫松华
 */
@Mapper
public interface WorksMapper extends BaseMapper<Works> {
    @Select("SELECT \n" +
            "    w.id,\n" +
            "    w.user_id,\n" +
            "    w.appointor_id,\n" +
            "    w.work_status_id,\n" +
            "    w.priority_id,\n" +
            "    w.attachments_id,\n" +
            "    w.title,\n" +
            "    w.content,\n" +
            "    w.`require`,\n" +
            "    w.create_time,\n" +
            "    w.update_time,\n" +
            "    w.end_time,\n" +
            "    w.deletion_state,\n" +
            "    u.name AS create_name,\n" +
            "    GROUP_CONCAT(att.name SEPARATOR ', ') AS attachment_names\n" +
            "FROM works AS w \n" +
            "LEFT JOIN\n" +
            "    user_info AS u ON u.user_id = w.user_id\n" +
            "LEFT JOIN\n" +
            "    attachments AS att ON att.id = w.attachments_id\n" +
            "GROUP BY  \n" +
            "    w.id,\n" +
            "    w.user_id,\n" +
            "    w.appointor_id,\n" +
            "    w.work_status_id,\n" +
            "    w.priority_id,\n" +
            "    w.attachments_id,\n" +
            "    w.title,\n" +
            "    w.content,\n" +
            "    w.`require`,\n" +
            "    w.create_time,\n" +
            "    w.update_time,\n" +
            "    w.end_time,\n" +
            "    w.deletion_state,\n" +
            "    u.name")
    List<Work1> getTaskList();



    @Select("SELECT \n" +
            "    w.id,\n" +
            "    w.user_id,\n" +
            "    w.appointor_id,\n" +
            "    w.work_status_id,\n" +
            "    w.priority_id,\n" +
            "    w.attachments_id,\n" +
            "    w.title,\n" +
            "    w.content,\n" +
            "    w.`require`,\n" +
            "    w.create_time,\n" +
            "    w.update_time,\n" +
            "    w.end_time,\n" +
            "    w.deletion_state,\n" +
            "    u.name AS create_name,\n" +
            "    GROUP_CONCAT(att.name SEPARATOR ', ') AS attachment_names\n" +
            "FROM works AS w \n" +
            "LEFT JOIN\n" +
            "    user_info AS u ON u.user_id = w.user_id\n" +
            "LEFT JOIN\n" +
            "    attachments AS att ON att.id = w.attachments_id " +
            "WHERE w.title LIKE CONCAT('%', COALESCE(#{title}, ''), '%') " +
            "AND w.content LIKE CONCAT('%', COALESCE(#{content}, ''), '%') " +
            "AND w.work_status_id=#{workStatusId} " +
            "AND w.create_time>=#{createTime} " +
            "AND w.end_time<=#{endTime} " +
            "GROUP BY  \n" +
            "    w.id,\n" +
            "    w.user_id,\n" +
            "    w.appointor_id,\n" +
            "    w.work_status_id,\n" +
            "    w.priority_id,\n" +
            "    w.attachments_id,\n" +
            "    w.title,\n" +
            "    w.content,\n" +
            "    w.`require`,\n" +
            "    w.create_time,\n" +
            "    w.update_time,\n" +
            "    w.end_time,\n" +
            "    w.deletion_state,\n" +
            "    u.name")
    List<Works> getAssignedList(AdminWorkParam param);
}
